﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class Carrier_N : FormBase1
    {
        private int count = 0;
        string caname = "";
        public delegate void DoAction(string CarrierName);//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        public Carrier_N()
        {
            InitializeComponent();
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            vaildbefore();
            if (dxValidationProvider1.Validate())
            {
                SVC.client.Carrier ca = new SVC.client.Carrier();
                ca.CarrierName = te_name.Text;
                string r = my.bw.Carrier_Add(ca, my.ACID);
                if (string.IsNullOrEmpty(r))
                {
                    count++;
                    caname = te_name.Text;
                    reset();
                }
                else
                {
                    Comm.ShowErorr(r);
                }
            }
        }

        private void vaildbefore()
        {
            te_name.Text = te_name.Text.Trim();
        }
        void reset()
        {
            te_name.Text = "";
        }

        private void btn_nowclose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            vaildbefore();
            if (dxValidationProvider1.Validate())
            {
                SVC.client.Carrier ca = new SVC.client.Carrier();
                ca.CarrierName = te_name.Text;
                string r = my.bw.Carrier_Add(ca, my.ACID);
                if (string.IsNullOrEmpty(r))
                {
                    count++;
                    caname = te_name.Text;
                    this.Close();
                }
                else
                {
                    Comm.ShowErorr(r);
                }
            }
        }

        private void Carrier_N_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (count > 0)
            {
                FatherRefresh(caname);
            }
        }
    }
}